<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Models\Withdraw;
use Encore\Admin\Form;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Grid;

class WithdrawController extends Controller
{
    protected $name = '提现管理';
    use ModelForm;
    
    
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header($this->name);
            $content->description($this->name);


            $content->body($this->grid());
        });
    }
    
    /**
     * Edit interface.
     *
     * @param $id
     *
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header($this->name);
            $content->description('编辑');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header($this->name);
            $content->description('创建');

            $content->body($this->form());
        });
    }
    
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Withdraw::class, function (Grid $grid) {
            $grid->model()->orderBy('id', 'DESC');
            
            $grid->filter(function($filter){
                $filter->disableIdFilter();
                $filter->like('name', '账户名称');
				$filter->like('mobile', '电话');
                //$filter->addFilter($filter->like('post_title', '标题'));
                $filter->equal('status', '类型')->select(Withdraw::$status);
            
            });
            $grid->column('id', 'ID')->sortable();
            $grid->column('name', '账户名称');
            $grid->column('mobile', '电话');
            $grid->column('money', '金额');
            $states = [
                'on'  => ['value'=>1,'text' => '已审核', 'color' => 'primary'],
                'off' => ['value'=>0,'text' => '未审核', 'color' => 'default'],
            ];
            $grid->column('status', '状态')->switch($states);
            
            
            $grid->column('updated_at', '更新时间');
        });
    }
    
    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        
        return Admin::form(Withdraw::class, function (Form $form) {
            
            $form->number('id', 'ID')->attribute('disabled', false);
            $form->text('name', '账户名称');
            $form->text('mobile', '电话');
            $form->text('account', '账户');
			$form->radio('acctounttype','账户类型')->options(['1' => '微信', '2'=> '支付宝']);
            
            $form->number('money', '金额');
			$form->radio('status','审核状态')->options(['1' => '是', '0'=> '否']);
            
            $form->saving(function($form){
                if($form->status == 'on')
                {
                    $form->status = 1;
					//生成提交记录
					
                }else{
                    $form->status = 0;
                }
            });
        });
    }
}
